<?php

if ($model)
{

    $staffs      = Receipt::getStaffName($perform);
    $dateReceipt = $model->formatDate;

    echo " <div style='width: 100%'>
            <div style='width: 90%;margin: 0 auto'>
                <div style='width: 50%; text-align: left ; float: left'>
                    <img src='{$model->order->fullLinkImage}'>
                    <div style='width: 50%;'>
                    <br>{$model->order->service->user->address}
                    <br>{$model->order->service->user->office_phone}
                    </div>
                </div>
                <div style='width: 50%; text-align: right;float: left'>
                    <p> RECEIPT  </p>
                    <table cellspacing='0' style='text-align: left;float: right;'>
                        <tr> 
                            <td>Date:</td>
                            <td style='border:1px solid #ccc;padding: 5px'>{$dateReceipt}</td>
                        </tr>
                        <tr>
                            <td>Receipt #:</td>
                            <td style='border:1px solid #ccc;padding: 5px'>$model->receipt_key</td>
                        </tr> 
                    </table>  
                    <div style='clear: both'></div>
                </div>
                <div style='clear: both'></div>
                <div style='width: 70%; margin-top: 30px'>
                    <table cellspacing='0' style='width: 46%;float: 
                           left;border: 1px solid gray;'>
                        <tr>
                            <td style='border-bottom: 1px solid gray;padding: 5px'>
                                Bill To: 
                            </td>
                        </tr>
                        <tr>
                            <td style='padding: 5px'>
                                <b style='line-height: 35px;'>{$model->order->customer->name}</b>
                                <br>{$model->order->customer->address}<br>
                                {$model->order->customer->city},
                                {$model->order->customer->postal_code}<br>
                                {$model->order->customer->country}<br>
                                {$model->order->customer->phone}<br>
                            </td>
                        </tr>
                    </table>
                    <table cellspacing='0' style='margin-left: 20px;width: 46%;float: left;
                           border: 1px solid gray;'>
                        <tr>
                            <td style='border-bottom: 1px solid gray;padding: 5px'>
                                Payment Information:
                            </td>
                        </tr>
                        <tr>
                            <td style='padding: 5px'>
                                <b style='line-height: 35px;'>{$model->order->customer->name}</b>
                                <br>
                                {$payment->methodLabel} {$payment->payment_key}<br>
                                PAID: $$payment->amount
                            </td>
                        </tr>
                    </table>
                    <div style='clear: both'></div>
                </div>
                <table cellspacing='0' border='1' style='text-align: left;margin-top: 10px;width: 100%; '>
                    <thead>
                    <th style='padding:5px 10px'>Item</th>
                    <th style='padding:5px 10px'>Employee/Commission To</th>
                    <th style='padding:5px 10px'>List Price</th>
                    <th style='padding:5px 10px'>Qty</th>
                    <th style='padding:5px 10px'>Discount</th>
                    <th style='padding:5px 10px'>Tax</th>
                    <th style='padding:5px 10px'>Total Price</th>
                    </thead>
                    <tbody>
                        <tr>
                            <td style='padding:5px 10px'>
                               {$model->item_description}
                            </td>
                            <td style='padding:5px 10px'>
                               {$staffs}
                            </td>
                            <td style='padding:5px 10px'>
                               $$model->list_price
                            </td>
                            <td style='padding:5px 10px'>  {$model->qty}</td>
                            <td style='padding:5px 10px'>
                            $model->discount $model->discount_type";
    if ($model->order->packageOrder)
    {
        $package    = $model->order->packageOrder->packageCustomer->package;
        $pack_price = $package->price / $package->limit;
        echo "<br>Package discount: -$$pack_price";
    }
    echo "</td>
                            <td style='padding:5px 10px'>  {$model->getTypeByTax()}</td>
                            <td style='padding:5px 10px'>$$model->final_price</td>
                        </tr>
                    </tbody>
                </table><br>";
    if ($model->order->retailOrder)
    {
        echo "<table cellspacing='0' border='1' style='text-align: left;margin-top: 10px;width: 100%; '>
                        <thead>
                        <th style='padding:5px 10px'>Retail Item Name</th>
                        <th style='padding:5px 10px'>Price</th>
                        <th style='padding:5px 10px'>Quantity</th>
                        <th style='padding:5px 10px'>Total</th>
                        </thead>
                        <tbody>";
        foreach ($model->order->retailOrder->items as $v)
        {
            $_subprice = $v->qty * $v->item->price;
            echo "<tr>
                                    <td style='padding:5px 10px'>{$v->item->name}</td>
                                    <td style='padding:5px 10px'>$" . $v->item->price . "</td>
                                    <td style='padding:5px 10px'>$v->qty</td>
                                    <td style='padding:5px 10px'>$" . $_subprice . "</td>
                                </tr>";
        }

        echo "<tr>
                                <td style='padding:5px 10px' colspan='4'>
                                    Discount &nbsp;{$model->order->retailOrder->receipt->discount}
                                    &nbsp;(";

        if ($model->order->retailOrder->receipt->discount_type == '$')
        {
            echo 'Money';
        }
        else
        {
            echo 'Percent';
        }
        echo ")
                                    <br>
                                    Tax:&nbsp;$" . $model->order->retailOrder->receipt->tax .
        "</td>
                            </tr>
                            <tr>
                                <td colspan='4'>
                                    Total: $" . $model->order->retailOrder->receipt->final_price .
        "</td>
                            </tr>
                        </tbody>
                    </table>";
    }

    echo "<div style='clear: both'></div>
            </div>
        </div>";
}